home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
src.arc
/
IPDUMP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-19
|
2KB
|
80 lines
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "internet.h"
#include "timer.h"
#include "iface.h"
#include "ip.h"
#include "trace.h"
#include "netuser.h"
void
ip_dump(bpp,check)
struct mbuf **bpp;
int check;
{
struct ip ip;
int16 ip_len;
int16 length;
int16 csum;
if(bpp == NULLBUFP || *bpp == NULLBUF)
return;
printf("IP:");
/* Sneak peek at IP header and find length */
ip_len = ((*bpp)->data[0] & 0xf) << 2;
if(ip_len < IPLEN){
printf(" bad header\n");
return;
}
if(check)
csum = cksum(NULLHEADER,*bpp,ip_len);
else
csum = 0;
ntohip(&ip,bpp); /* Can't fail, we've already checked ihl */
/* Trim data segment if necessary. */
length = ip.length - ip_len; /* Length of data portion */
trim_mbuf(bpp,length);
printf(" len %u",ip.length);
printf(" %s",inet_ntoa(ip.source));
printf("->%s ihl %u ttl %u",
inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
if(ip.tos != 0)
printf(" tos %u",uchar(ip.tos));
if(ip.offset != 0 || ip.flags.mf)
printf(" id %u offs %u",ip.id,ip.offset);
if(ip.flags.df)
printf(" DF");
if(ip.flags.mf){
printf(" MF");
check = 0; /* Bypass host-level checksum verify */
}
if(csum != 0)
printf(" CHECKSUM ERROR (%u)",csum);
if(ip.offset != 0){
printf("\n");
return;
}
switch(uchar(ip.protocol)){
case TCP_PTCL:
printf(" prot TCP\n");
tcp_dump(bpp,ip.source,ip.dest,check);
break;
case UDP_PTCL:
printf(" prot UDP\n");
udp_dump(bpp,ip.source,ip.dest,check);
break;
case ICMP_PTCL:
printf(" prot ICMP\n");
icmp_dump(bpp,ip.source,ip.dest,check);
break;
default:
printf(" prot %u\n",uchar(ip.protocol));
break;
}
}